package org.oc.qaq.controller;

import org.oc.qaq.dto.TagDTO;
import org.oc.qaq.entity.Tag;
import org.oc.qaq.result.Result;
import org.oc.qaq.service.TagService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/tags")
public class TagController {


    private final TagService tagService;

    public TagController(TagService tagService) {
        this.tagService = tagService;
    }

    @GetMapping
    public Result<?> tags() {
        return Result.success(tagService.getTags());
    }

    @PostMapping
    public Result<?> addTag(@RequestBody TagDTO tagDTO) {
        tagService.addTag(tagDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        tagService.delete(id);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody TagDTO tagDTO) {
        tagService.updateTag(tagDTO);
        return Result.success();
    }

    @PostMapping("/tag/{fileId}")
    public Result<?> tagFile(@PathVariable String fileId,
                             @RequestBody List<Long> tags) {
        tagService.tagFile(fileId, tags);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result<?> deleteBatch(@RequestBody List<Long> ids) {
        tagService.deleteBatch(ids);
        return Result.success();
    }
}
